﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp18
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //读取短信模板
            string tempalteText = string.Empty;
            string templateFileName = "全院消息管理软件接口请求参数模板.json";
            string templateFileFullName = Path.Combine("D:\\", templateFileName);
            using (StreamReader streamReader = new StreamReader(templateFileFullName))
            {
                tempalteText = streamReader.ReadToEnd();
            }
            JObject jObject = JsonConvert.DeserializeObject(tempalteText) as JObject;
            JArray jArray = jObject.SelectToken("Request.RequestBody.ContactList") as JArray;
           
            JToken newToken = JToken.Parse("{\r\n          \"ChannelCode\": \"0003\",\r\n          \"Contact\": \"${Contact}\"\r\n        }");

        }

        private void button2_Click(object sender, EventArgs e)
        {
            #region 创建json对象

            Console.WriteLine("\n\n1--创建json对象:");
            JObject staff = new JObject();
            staff.Add(new JProperty("Name", "Jack"));//等价于staff.Add("Name","Jack");
            staff.Add(new JProperty("Age", 33));
            staff.Add(new JProperty("Department", "Personnel Department"));
            JArray jArray = new JArray();
            jArray.Add(new JObject(new JProperty("Name", "Tom"), new JProperty("Age", 44), new JProperty("Department", "Personnel Department")));
            jArray.Add(new JObject(new JProperty("Name", "Tom2"), new JProperty("Age", 44), new JProperty("Department", "Personnel Department")));
           
            staff.Add(new JProperty("Leader", jArray));

            staff.Remove("Department");
            jArray = new JArray();
            jArray.Add("111");
            jArray.Add("222");
            staff.Add(new JProperty("Department", jArray));

            Console.WriteLine(staff.ToString());
       
            textBox1.Text = staff.ToString();
            #endregion
        }
    }
}
